home *** CD-ROM | disk | FTP | other *** search
- Path: mail2news.demon.co.uk!ues5.cern.ch
- From: Dan Pop <danpop@ues5.cern.ch>
- Newsgroups: comp.lang.c
- Subject: Re: Question about sscanf
- Date: Fri, 9 Feb 1996 21:33:24 +0100
- Message-ID: <9602092033.AA07743@ues5.cern.ch>
- References: <4fe1oq$kuf@zippy.cais.net>
- X-NNTP-Posting-Host: ues5.cern.ch
- X-Newsreader: NN version 6.5.0 #7 (NOV)
- X-Mail2News-Path: mail1.cern.ch!ues5.cern.ch
-
- In <4fe1oq$kuf@zippy.cais.net> usaid@cais.cais.com (USAID) writes:
-
- >Here is a fragment of code that I'm having a problem with. The program
- >is bombing on the line containing the call to sscanf. It assigns to the
- >first variable fine, but blows up on the second one. I have no idea
- >what's wrong.
- >
- >int formatFile(void)
- >{
- > int i;
- > char line[MAX_LINE_LEN + 1];
- > char *name;
- > char *value;
- > char *val[MAXREGIONS];
- > char *delimiter = ", ";
- > FILE *ifp, *ofp;
- >
- > /* open input and output files */
- > ifp = fopen("/opt/basis/tcs/formdata/test.txt", "r");
- > ofp = fopen("/opt/basis/tcs/formdata/import.txt", "w");
- > if ((ifp == NULL) || (ofp == NULL))
- > return (0);
- >
- > while (fgetline(ifp, line, MAX_LINE_LEN) != -1)
- > {
- > /* store the name and value in variables */
- > if (sscanf(line, "%s %s", name, value) != 2)
- > {
- > printf("Bad input from sscanf\n");
- > return (0);
- > }
- > .
- > .
- > .
- > }
- >}
-
- After turning this snippet into a valid C translation unit, this is
- what I've got:
-
- ues5:~/Files 88> gcc -c -Wuninitialized -O usaid.c
- usaid.c: In function `formatFile':
- usaid.c:8: warning: `name' might be used uninitialized in this function
- usaid.c:9: warning: `value' might be used uninitialized in this function
-
- Does this ring a bell? If not, read the FAQ.
-
- Dan
- --
- Dan Pop
- CERN, CN Division
- Email: danpop@mail.cern.ch
- Mail: CERN - PPE, Bat. 31 R-004, CH-1211 Geneve 23, Switzerland
-